package com.yuan.SMS.controller;

import com.alibaba.fastjson.JSON;
import com.yuan.SMS.bean.QueryInfo;
import com.yuan.SMS.bean.Student;
import com.yuan.SMS.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class StudentController {

    @Autowired
    StudentDao sdao;

    @RequestMapping("/findAll")
    @CrossOrigin("http://localhost:8080")
    public String getStudentList(QueryInfo queryInfo){
        //获取最大列表数
        int numbers = sdao.getStudentCounts();
        int pageStart = (queryInfo.getPageNum() -1) * queryInfo.getPageSize();

        List<Student> students = sdao.findAllStudent(pageStart, queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("number", numbers);
        res.put("data", students);
        return JSON.toJSONString(res);
    }
}
